package com.hadoopSpark.application.test;

/*
 * 显示应用的基本信息
 * 这个，必须是脚本来调用的，
 */
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import com.aliyun.configuration.ConfigurationTool;
import com.aliyun.util.String2JsonTool;
import com.certificate.tool.SetTrustStore;
import com.common.constant.Constant;

public class ShowAppBaseInfo2 {

	public static void main(String[] args) throws Exception {

		SSLConnectionSocketFactory sslsf = SetTrustStore.getSSLConnection();

		// httpclient链接
		CloseableHttpClient httpClient = HttpClients.custom()
				.setSSLSocketFactory(sslsf).build();

		try {
			HttpGet httpGet = null;
			if (!args[0].equals("")) {// 说明用户，传入了参数， 这个是，查看集群的详细信息，如查看某个应用实例
				httpGet = new HttpGet(
						ConfigurationTool.getProperties(Constant.ALIYUN_PROJECTS_URL)
								+ args[0]);

			} else { // 等于0，说明，用户，没有传入参数，就是查看整个集群的信息
				httpGet = new HttpGet(
						ConfigurationTool.getProperties(Constant.ALIYUN_PROJECTS_URL));
			}

			CloseableHttpResponse httpResponse = httpClient.execute(httpGet);

			try {
				
				//输出协议，响应码，结果
				System.out.println(httpResponse.getProtocolVersion() + " "
						+ httpResponse.getStatusLine().getStatusCode() + " "
						+ httpResponse.getStatusLine().getReasonPhrase());
				
				String bodyAsString = EntityUtils.toString(httpResponse.getEntity());

				String2JsonTool.printJson(bodyAsString);

			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				httpResponse.close();
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			httpClient.close();
		}
	}
}
